package com.masiyi.filter.test;

import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.annotation.WebFilter;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author masiyi
 * @Date 2023/12/6
 * @PackageName:com.masiyi.filter
 * @ClassName: MyFilter
 * @Description: TODO
 * @Version 1.0
 */

@WebFilter(urlPatterns = "/myFilter/*")
public class MyFilter implements Filter {
    /**
     * @param filterConfig
     * @throws ServletException
     */
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        // 在这里编写过滤器的逻辑
        // 可以对请求进行处理，然后调用 chain.doFilter(request, response) 继续执行过滤链
        chain.doFilter(request, response);
        System.out.println(response);
    }
    /**
     *
     */
    @Override
    public void destroy() {
        System.out.println("销毁");
        Filter.super.destroy();
    }
}
